import { Component, Input, ViewChild } from '@angular/core';
import { DataTableComponent, TableWidthConfig } from 'ng-devui';
import { SharedMethodService } from 'src/app/@core/services/Sharedmethod/shared-method.service';
import { JobOrderService } from 'src/app/@core/services/jobOrder/job-order.service';

@Component({
  selector: 'app-select-return-material-jober',
  templateUrl: './select-return-material-jober.component.html',
  styleUrls: ['./select-return-material-jober.component.scss']
})
export class SelectReturnMaterialJoberComponent {
  @Input() data: any;
  isSelected = false;
  displayTableData: any[] = [];
  tableheight = '230px';
  selectData:any;
  searchName:''
  pager = {
    total: 20,
    pageIndex: 1,
    pageSize: 20
  };
  pageSizeOptions = [10, 20, 30, 50, 100];
  dataTableOptions={
    columns:[

      {
        field: '工单号',
        header: '工单号',
        fieldType: 'text',
      },

      {
        field: '工序序号',
        header: '工序序号',
        fieldType: 'text',
      },
      {
        field: '工序编码',
        header: '工序编码',
        fieldType: 'text',
      },
      {
        field: '工序名称',
        header: '工序名称',
        fieldType: 'text',
      },
      {
        field: '产品编码',
        header: '产品编码',
        fieldType: 'text',
      },
      {
        field: '产品名称',
        header: '产品名称',
        fieldType: 'text',
      },
      {
        field: '产品规格',
        header: '产品规格',
        fieldType: 'text',
      },
      {
        field: '操作工',
        header: '操作工',
        fieldType: 'text',
      },
      {
        field: '状态',
        header: '状态',
        fieldType: 'text',
      },
      {
        field: '计划数',
        header: '计划数',
        fieldType: 'text',
      },

      {
        field: '完成进度',
        header: '完成进度',
        fieldType: 'text',
      },
      {
        field: '剩余数',
        header: '剩余数',
        fieldType: 'text',
      },

      {
        field: '计划开工时间',
        header: '计划开工时间',
        fieldType: 'text',
      },
      {
        field: '计划完工时间',
        header: '计划完工时间',
        fieldType: 'text',
      },
    ]
  }
  tableWidthConfig: TableWidthConfig[] = [
    {
      field: 'checkbox',
      width: '80px'
    },
    {
      field: '工单号',
      width: '140px'
    },
    {
      field: '工序序号',
      width: '160px'
    },

    {
      field: '工序编码',
      width: '150px'
    },
    {
      field: '工序名称',
      width: '100px'
    },
    {
      field: '规格型号',
      width: '100px'
    },
    {
      field: '工序序号',
      width: '100px'
    },
    {
      field: '工序',
      width: '100px'
    },
    {
      field: '操作工',
      width: '100px'
    },
    {
      field: '状态',
      width: '100px'
    },
    {
      field: '计划数',
      width: '100px'
    },
    {
      field: '完成进度',
      width: '150px'
    },
    {
      field: '剩余数',
      width: '100px'
    },

    {
      field: '计划开工时间',
      width: '100px'
    },
    {
      field: '计划完工时间',
      width: '100px'
    },
  ]
  weiwai: string
  getParts:any ={}
  partNum: string = null;
  partName: string = null;
  JobOrderNum: string = null;
  JobOrderStatus: string = null;
  JobOrderType: string = null;
  StartDate: string = null;
  EndDate: string = null;
  jobOrderProcesses:any[]=[];
  productJob=[]
  tableData=[];
  checkRows:any[]=[];
  PartNum:string = null;
  PartName:string = null;
  ProcessNum:string = null;
  ProcessName:string = null;
  isIconRotated = false;
  @ViewChild(DataTableComponent, { static: true }
  ) datatable!: DataTableComponent;//获取table
  constructor(private SharedMethodService:SharedMethodService,private JobOrderService:JobOrderService) { }
  ngOnInit(): void {
    this.JobOrderService.GetJobOrdersProcess2(this.PartNum,this.PartName,this.JobOrderNum,"已领料",this.ProcessNum,this.ProcessName,this.pager.pageIndex,this.pager.pageSize,null,true).subscribe((data:any)=>{
      this.tableData=data.items
      this.pager.total=data.totalCount;
    })
  }
  pageIndexChange($event: any) {
    this.search()
  }//切换页码
  pageSizeChange($event: any){
    this.search()
  }//改变每页显示数量
  search(){
    this.JobOrderService.GetJobOrdersProcess2(this.PartNum,this.PartName,this.JobOrderNum,"已领料",this.ProcessNum,this.ProcessName,this.pager.pageIndex,this.pager.pageSize,null,true).subscribe((data:any)=>{
      this.tableData=data.items
      this.pager.total=data.totalCount;
    })
  }
  search2(){
    this.pager.pageIndex = 1
    this.JobOrderService.GetJobOrdersProcess2(this.PartNum,this.PartName,this.JobOrderNum,"已领料",this.ProcessNum,this.ProcessName,this.pager.pageIndex,this.pager.pageSize,null,true).subscribe((data:any)=>{
      this.tableData=data.items
      this.pager.total=data.totalCount;
    })
  }
  reset(){
    this.PartNum = null;
    this.PartName = null;
    this.ProcessNum = null;
    this.ProcessName = null;
    this.JobOrderNum = null;
    this.search()
  }
  onRowCheckChange(checked: any, rowIndex: any, nestedIndex: any, rowItem: { $checked: any; $halfChecked: boolean; }) {
    this.SharedMethodService.onRowCheckChange(checked, rowIndex, nestedIndex, rowItem, this.datatable)
    this.getParts={
      pageNumber:1,
      pageSize:999,
      jobOrderProcessIds:this.checkRows
     }
  }
  getCheckedRows() {
    this.SharedMethodService.getCheckedRows(this.datatable, 'jobOrderProcessId').subscribe((data: any) => {
      this.checkRows = data;
      this.getParts={
        pageNumber:1,
        pageSize:999,
        jobOrderProcessIds:this.checkRows
       }
    })
  }//获取选中行
  cleared() {
    this.SharedMethodService.cleared(this.checkRows, this.checkRows, this.datatable).subscribe((data: any) => {
      this.checkRows = data;
    })
  }//清空选中行
}
